<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_themeUnique"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/maplibregl/include-maplibregl.js"></script>
<span id="show"></span>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";

    var attribution = "<a href='https://maplibre.org/' target='_blank'>© MapLibre </a>" +
       "with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
       " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";

    var dataUrl = host + "/iserver/services/map-china/rest/maps/China";
    var map = new maplibregl.Map({
        container: 'map',
        style: {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "attribution": attribution,
                    "type": "raster",
                    "tiles": [host + '/iserver/services/map-china/rest/maps/China/zxyTileImage.png?prjCoordSys='+encodeURIComponent('{"epsgCode":3857}')+'&z={z}&x={x}&y={y}'],
                    "tileSize": 256,
                },
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
                "minzoom": 0,
                "maxzoom": 22
            }]
        },
        center: [110, 39],
        zoom: 4
    });
    map.addControl(new maplibregl.NavigationControl(), 'top-left');
    map.addControl(new maplibregl.supermap.LogoControl({ link: "https://iclient.supermap.io" }), 'bottom-right');

    function createTheme() {
        var style1, style2, style3, style4, style5, style6;
        style1 = new maplibregl.supermap.ServerStyle({
            fillForeColor: new maplibregl.supermap.ServerColor(248, 203, 249),
            lineColor: new maplibregl.supermap.ServerColor(255, 255, 255),
            lineWidth: 0.1
        });
        style2 = new maplibregl.supermap.ServerStyle({
            fillForeColor: new maplibregl.supermap.ServerColor(196, 255, 189),
            lineColor: new maplibregl.supermap.ServerColor(255, 255, 255),
            lineWidth: 0.1
        });
        style3 = new maplibregl.supermap.ServerStyle({
            fillForeColor: new maplibregl.supermap.ServerColor(255, 173, 173),
            lineColor: new maplibregl.supermap.ServerColor(255, 255, 255),
            lineWidth: 0.1
        });
        style4 = new maplibregl.supermap.ServerStyle({
            fillForeColor: new maplibregl.supermap.ServerColor(255, 239, 168),
            lineColor: new maplibregl.supermap.ServerColor(255, 255, 255),
            lineWidth: 0.1
        });
        style5 = new maplibregl.supermap.ServerStyle({
            fillForeColor: new maplibregl.supermap.ServerColor(173, 209, 255),
            lineColor: new maplibregl.supermap.ServerColor(255, 255, 255),
            lineWidth: 0.1
        });
        style6 = new maplibregl.supermap.ServerStyle({
            fillForeColor: new maplibregl.supermap.ServerColor(132, 164, 232),
            lineColor: new maplibregl.supermap.ServerColor(255, 255, 255),
            lineWidth: 0.1
        });

        var themeUniqueIteme1 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "黑龙江省",
                style: style1
            }),
            themeUniqueIteme2 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "湖北省",
                style: style2
            }),
            themeUniqueIteme3 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "吉林省",
                style: style3
            }),
            themeUniqueIteme4 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "内蒙古自治区",
                style: style4
            }),
            themeUniqueIteme5 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "青海省",
                style: style5
            }),
            themeUniqueIteme6 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "新疆维吾尔自治区",
                style: style6
            }),
            themeUniqueIteme7 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "云南省",
                style: style1
            }),
            themeUniqueIteme8 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "四川省",
                style: style4
            }),
            themeUniqueIteme9 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "贵州省",
                style: style3
            }),
            themeUniqueIteme10 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "甘肃省",
                style: style3
            }),
            themeUniqueIteme11 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "宁夏回族自治区",
                style: style5
            }),
            themeUniqueIteme12 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "重庆市",
                style: style6
            }),
            themeUniqueIteme13 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "山东省",
                style: style1
            }),
            themeUniqueIteme14 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "安徽省",
                style: style2
            }),
            themeUniqueIteme15 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "江西省",
                style: style3
            }),
            themeUniqueIteme16 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "浙江省",
                style: style4
            }),
            themeUniqueIteme17 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "台湾省",
                style: style2
            }),
            themeUniqueIteme18 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "江苏省",
                style: style6
            }),
            themeUniqueIteme19 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "湖南省",
                style: style5
            }),
            themeUniqueIteme20 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "河南省",
                style: style4
            }),
            themeUniqueIteme21 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "河北省",
                style: style3
            }),
            themeUniqueIteme22 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "福建省",
                style: style5
            }),
            themeUniqueIteme23 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "广西壮族自治区",
                style: style6
            }),
            themeUniqueIteme24 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "西藏自治区",
                style: style2
            }),
            themeUniqueIteme25 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "广东省",
                style: style4
            }),
            themeUniqueIteme26 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "山西省",
                style: style2
            }),
            themeUniqueIteme27 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "陕西省",
                style: style1
            }),
            themeUniqueIteme28 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "天津市",
                style: style5
            }),
            themeUniqueIteme29 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "北京市",
                style: style2
            }),

            themeUniqueIteme30 = new maplibregl.supermap.ThemeUniqueItem({
                unique: "辽宁省",
                style: style1
            });

        var themeUniqueItemes = [
            themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3, themeUniqueIteme4, themeUniqueIteme5,
            themeUniqueIteme6, themeUniqueIteme7, themeUniqueIteme8, themeUniqueIteme9, themeUniqueIteme10,
            themeUniqueIteme11, themeUniqueIteme12, themeUniqueIteme13, themeUniqueIteme14, themeUniqueIteme15,
            themeUniqueIteme16, themeUniqueIteme17, themeUniqueIteme18, themeUniqueIteme19, themeUniqueIteme20,
            themeUniqueIteme21, themeUniqueIteme22, themeUniqueIteme23, themeUniqueIteme24, themeUniqueIteme25,
            themeUniqueIteme26, themeUniqueIteme27, themeUniqueIteme28, themeUniqueIteme29, themeUniqueIteme30
        ];

        var themeUnique = new maplibregl.supermap.ThemeUnique({
            uniqueExpression: "Name",
            items: themeUniqueItemes,
            defaultStyle: style1
        });
        var themeParameters = new maplibregl.supermap.ThemeParameters({
            datasetNames: ["Province_R"],
            dataSourceNames: ["China"],
            themes: [themeUnique]
        });

        new maplibregl.supermap.ThemeService(dataUrl).getThemeInfo(themeParameters).then(function (serviceResult) {
            var result = serviceResult.result;
            if (result && result.newResourceID) {
                map.addSource("theme", {
                    "type": 'raster',
                    "tiles": [host + '/iserver/services/map-china/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}&noWrap=true&transparent=true&cacheEnabled=false&layersID=' + result.newResourceID],
                    "tileSize": 256,
                });

                map.addLayer({
                    "id": "themeLayer",
                    "type": "raster",
                    "source": "theme",
                });
            }
        })
    }

    map.on('load', function () {

        createTheme();
    });

</script>

</body>
</html>